const completeDate = (val) => {
	return val < 10 ? "0" + val : val;
}

//获取当前日期，格式YYYY-MM-DD
const getNowFormatDay = (nowDate) => {
	let char = "-";
	if (nowDate == null) {
		nowDate = new Date();
	}
	let day = nowDate.getDate();
	let month = nowDate.getMonth() + 1;
	let year = nowDate.getFullYear();
	return year + char + completeDate(month) + char + completeDate(day);
}

//获取当前时间，格式YYYY-MM-DD HH:mm:ss
const getNowFormatTime = () => {
	let nowDate = new Date();
	let colon = ":";
	let h = nowDate.getHours();
	let m = nowDate.getMinutes();
	let s = nowDate.getSeconds();
	return getNowFormatDay(nowDate) + " " + completeDate(h) + colon + completeDate(m) + colon + completeDate(s);
}

module.exports = {
	completeDate,
	getNowFormatDay,
	getNowFormatTime
}
